$(function() {
	var grid;
	var url=null;
	var operation = {
			addFun : rootPath + '/consoleuser/addUI.shtml',
			editFun: rootPath + '/consoleuser/editUI.shtml?id=',
			delFun : rootPath + '/consoleuser/deleteEntity.shtml',
			
			competenceFun : rootPath + '/consoleuser/competenceUI.shtml?id=',
			permissionsFun : rootPath + '/consoleuser/permissions.shtml?id=' ,
		}
	$.ajax({
		url:rootPath + '/consoleuser/getButton.shtml',//请求获取按钮
		success:function(data){
			var button = data;
			if(button !== ''){
				  button = button.replace("\"","");
				  button = button.replace("\"","");
		        }
			grid = TableData({
				gaine : 'paging',//id名
				table:'consoleuser',
				column : [  {
					colkey : "enterprise",
					name : "企业",
				},{
					colkey : "name",
					name : "套餐",
				}, {
					colkey : "owner",
					name : "电话",
				}, {
					colkey : "real_pay",
					name : "实际付款",
				}, {
					colkey : "df_status",
					name : "状态",
					render : function(data, type, hashmap, meta) {
						if (hashmap.df_status == 1) {
							return "停用";
						}
						if (hashmap.df_status == 0) {
							return "正常";
						}
					}
				}, {
					colkey : "df_create_time",
					name : "创建时间",
					render:function(data,type,row,meta){
						function formatDate(now)   {     
				              var y=now.getFullYear(), m=now.getMonth()+1,d=now.getDate();     
				              //var h=now.getHours();     
				              //var m=now.getMinutes();     
				              //var s=now.getSeconds();     //"+h+":"+m+":"+s   
				              return y+"-"+m+"-"+d;  
			              }     
					    var data=new Date(data);  
						return formatDate(data);
					}
				}, {
					colkey : "operation",
					name : "操作",
					"orderable": false,
					render:function(data,type,row,meta){
						return button;
					}
				}
				],
				url : rootPath + '/consoleuser/saleRecord.shtml',//表格数据请求地址
				//button: data,
				success:function(){
					 //将事件绑定在body上
					 //将事件绑定在body上
					consoleuser = function(e){
						    var e = e||window.event;
						    var target = $(e.target || e.srcElement);
						    //新增
						    if(target.hasClass('addFun')){
						    	cover._Body();//防止多次点击
						    	var id = target.parent().parent().attr('dataid');
						    	_click(operation.addFun,'addFun',id)
						    }
						    // 编辑
						    if(target.hasClass('editFun')){
						    	cover._Body();//防止多次点击
						    	var id = target.parent().parent().attr('dataid');
						    	var  hashmap = _DataTable.row( target.parents('tr') ).data();
						    	_click(operation.editFun,'editFun',hashmap.id)
						    }
						   //  删除
						    if(target.hasClass('delFun')){
						    	cover._Body();//防止多次点击
						    	var id = target.parent().parent().attr('dataid');
						    	_click(operation.delFun,'delFun',id)
						    }
						    // 下拉选择
						    if(target.hasClass('editdropdownFun')){
						    	cover._Body();//防止多次点击
						    	var id = target.parent().parent().attr('dataid');
						    	_click(operation.editdropdownFun,'editdropdownFun',id)
						    }
						    //  修改权限
						    if(target.hasClass('competenceFun')){
						    	cover._Body();//防止多次点击
						    	var id = target.parent().parent().attr('dataid');
						    	var  hashmap = _DataTable.row( target.parents('tr') ).data();
						    	var url = operation.permissionsFun + id+"&db_name="+hashmap.db_name+"&cellphone="+hashmap.cellphone;
				                $.get(url,function(data){
				                	layer.closeAll();
				                	cover.closeAll();// 解除多次点击限制
				                    layer.open({
				                        title : "权限设置",
				                        type : 1,
				                        area : ["auto","80%"],
				                        content : data
				                    });
				                })
						    }
					   }
					   $("#consoleuser_wrapper").off("click", consoleuser);//这个鬼东西，不知道是什么来的
					   $("#consoleuser_wrapper").on('click', consoleuser);
					   $("#consoleuser_wrapper ").on("click","[name=enterprise]",function(){
						   cover._Body();//防止多次点击
					    	var id = $(this).parent().attr('dataid');
					    	var hashmap = _DataTable.row( $(this).parents('tr') ).data();
					    	var url =rootPath+ "/consoleuser/saleInfoUI.shtml?owner=" + hashmap.owner +"&db_name="+ hashmap.db_name;  
						   $.get(url,function(data){
			                	layer.closeAll();
			                	cover.closeAll();// 解除多次点击限制
			                    layer.open({
			                        title : "客户详情",
			                        type : 1,
			                        area : ["650px"],
			                        content : data
			                    });
			                })
					   });
				}
			 });
		}
	})

setInterval(function(){
		$("[name=enterprise]").css({
			"color":"#0099ff",
			"cursor":"pointer"
		});
	},500)
});
	
	